package com.rqbl.service.impl;

import com.rqbl.entity.Topic;
import com.rqbl.mapper.TopicMapper;
import com.rqbl.myutils.PageBean;
import com.rqbl.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TopicServiceImpl implements TopicService {
    @Autowired
    TopicMapper topicMapper;

    /**
     * 分页查询话题信息
     * @param pageBean
     * @return
     */
    @Override
    public List<Topic> getTopicsByPage(PageBean pageBean){
        pageBean.setTotalSize(topicMapper.selectTopicCount());
        int totalPage = pageBean.getTotalSize()/pageBean.getPageSize();
        if(pageBean.getTotalSize()%pageBean.getPageSize()!=0){
            totalPage++;
        }
        pageBean.setTotalPage(totalPage);
        return topicMapper.selectAllTopicsBySize((pageBean.getPage()-1)*pageBean.getPageSize(),pageBean.getPageSize());
    }
}
